define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'user_withdrawal_apply/index' + location.search,
                    add_url: 'user_withdrawal_apply/add',
                    edit_url: 'user_withdrawal_apply/edit',
                    del_url: 'user_withdrawal_apply/del',
                    multi_url: 'user_withdrawal_apply/multi',
                    import_url: 'user_withdrawal_apply/import',
                    table: 'user_withdrawal_appply',
                }
            });

            var table = $("#table");

            //当表格数据加载完成时
            table.on('load-success.bs.table', function (e, data) {
                //这里可以获取从服务端获取的JSON数据
                // console.log(data);
                //这里我们手动设置底部的值
                $("#total").text(data.extend.total);
                $("#deposit").text(data.extend.deposit);
                $("#wait").text(data.extend.wait);
                $("#yes").text(data.extend.yes);
                $("#spare").text(data.extend.spare);
            });

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                searchFormVisible: true,// 默认显示搜索条件
                search: false,// 搜索框
                // commonSearch: false,// 搜索按钮
                showToggle: false,// 切换视图
                showColumns: false,// 显示列
                showExport: false,// 导出按钮
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('ID')},
                        {field: 'user.nickname', title: __('User.nickname'), operate: 'LIKE'},
                        // {field: 'type', title: __('类型'), formatter: Table.api.formatter.normal, searchList: {1: __('微信'), 2: __('支付宝'), 3: __('银行卡')}},
                        // {field: 'name', title: __('Name'), operate: 'LIKE'},
                        // {
                        //     field:'extend',
                        //     title:__('提现信息'),
                        //     operate:false,
                        //     align:'left',
                        //     formatter:function(value,row,index){
                        //         var html = '';
                        //         if(row.type == 1 || row.type == 2){
                        //             html +='账号:'+ row.account;
                        //             html+='<br>';
                        //             html +=  '收款码：<a href="javascript:"><img class="img-sm img-center" src="'+ row.qrcode +'"></a>';
                        //         }
                        //         if(row.type == 3){
                        //             html+='姓名:'+ row.cardholder;
                        //             html+='<br>';
                        //             html+='电话:'+ row.mobile;
                        //             html+='<br>';
                        //             html+='银行:'+row.name;
                        //             html+='<br>';
                        //             html+='卡号:'+row.account;
                        //         }
                        //         return html;
                        //     }
                        // },
                        {field: 'money', title: __('提现金额'), operate:'BETWEEN'},
                        {field: 'order.order_no', title: __('相关工单'), operate:'LIKE'},
                        // {field: 'account', title: __('Account'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'qrcode', title: __('Qrcode'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'cardholder', title: __('Cardholder'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'mobile', title: __('Mobile'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'status', title: __('Status'), formatter: Table.api.formatter.status, searchList: {0: __('待审核'), 1: __('已通过'), 2: __('已拒绝'), 3: __('已完成')}},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));

                $(function () {
                    $('.img-center').on('click', function () {
                        var src = $(this).attr('src');
                        $('.imgPreview img').attr('src', src);
                        $('.imgPreview').show();
                    });
                    $('.imgPreview').on('click', function () {
                        $('.imgPreview').hide();
                    });
                })
            }
        }
    };
    return Controller;
});
